/**
 * ReportGear(2011)
 */
package com.reportgear.core.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.reportgear.report.core.api.idname.DefaultIdName;
import com.reportgear.report.core.api.idname.IdName;

/**
 * 数据访问相关
 * 
 * @version 1.0 2011-4-17
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 * @deprecated
 */
public class DataHelper {
	public List<IdName<Integer>> queryIdNameList(String sql) {
		List<IdName<Integer>> result = new ArrayList<IdName<Integer>>();
		Connection conn = this.getConnection();

		try {
			Statement stat = conn.createStatement();
			ResultSet rs = stat.executeQuery(sql);

			while (rs.next()) {
				result.add(new DefaultIdName<Integer>(rs.getInt(1), rs.getString(2)));
			}

			rs.close();
			stat.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return result;
	}

	public String getReportTemplate(int reportId) {
		String result = "";

		Connection conn = this.getConnection();
		String sql = "select strContent from ss_querytemplate where intid = " + reportId;
		try {
			Statement stat = conn.createStatement();
			ResultSet rs = stat.executeQuery(sql);

			if (rs.next()) {
				result = rs.getString(1);
			}

			rs.close();
			stat.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return result;
	}

	public Connection getConnection() {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");

			return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hrms", "hrms");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return null;
	}
}
